<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------

Route::get('think', function () {
    return 'hello,ThinkPHP5!';
});

Route::get('Hello/:name',function($name){
    return 'Hello,'.$name;
});

//全局设置
//\think\facade\Route::pattern([
//    'id'=>'/d+',
//    'uid'=>'/d+'
//]);

//静态路由
//Route::get('hello/:name', 'index/hello');
//think\facade\Route::get('/','index');
//think\facade\Route::get('ad','text/Address/index');
////静态动态结合的地址
//\think\facade\Route::get('details/:id','text/Address/details',['ext'=>'html'])   //ext 强制后缀是html
//                     ->name('det')
//                     ->pattern('id','\d+');   //严格限制必须只能是数字 \d+


//\think\facade\Route::rule('details/:id','text/Address/details','POST|GET');

//多参数静态动态结合的地址
//\think\facade\Route::get('search/:id/:uid','text/Address/search')
//                     ->pattern([
//                         'id'=>'\d+',
//                         'uid'=>'\d+'
//                     ]);

//规则完全匹配的地址
//\think\facade\Route::get('search/:id/:uid$','text/Address/search');

//\think\facade\Route::get('find/:id/[:content]','text/Address/find');
//
//\think\facade\Route::get('url','text/Address/url');
//
//
//\think\facade\Route::get('det-:name-<id>','text/Hello_:name/det');

//\think\facade\Route::get('short','text/Short/getInfo');
//\think\facade\Route::controller('short','text/Short');

//使用group()方法，来进行分组路由的注册
//方法1
//\think\facade\Route::group('col',[
//    ':id'=>  'text/Collect/read',
//    ':name'=> 'text/Collect/who'
//])->pattern(['id'=>'\d+$','name'=>'\w+$'])->ext('html')->https(false)->append(['flag'=>1]);
//方法2
//\think\facade\Route::group('col',function(){
//    \think\facade\Route::get(':id','text/Collect/read');
//    \think\facade\Route::get(':name','text/Collect/who');
//})->pattern(['id'=>'\d+$','name'=>'\w+$'])->ext('html')->https(false);
//方法3 使用prefix简化路由路径
//\think\facade\Route::group('col',function(){
//    \think\facade\Route::get(':id','read');
//    \think\facade\Route::get(':name','who');
//})->prefix('text/Collect/')->pattern(['id'=>'\d+$','name'=>'\w+$'])->ext('html')->https(false);

//\think\facade\Route::miss('text/public/miss');

//路由绑定
//\think\facade\Route::bind('cs02');
//\think\facade\Route::bind('cs02/User');


//路由别名
\think\facade\Route::alias('user','cs01/User')->ext('html');
//也可以直接绑定到类
//\think\facade\Route::alias('user','\app\cs01\controller\User');

//资源路由
//这里的blog表示资源规则名，Blog表示路由的访问路径
//资源路由注册成功后，会自动提供一下方法，不需要手动注册
//get 访问模式下: index(blog) ceate(blog/create) read(blog/:id) edit(blog/:id/edit)
//POST 访问模式下  save(blog)
//PUT 访问模式下 update(blog/:id)
// DELETE 方式模式下  delete(blog/:id)
\think\facade\Route::resource('blog','Blog');

//嵌套路由
//资源嵌套生成的路由规则如下
//http://localhost:8000/blog/:blog_id/comment/:id
//http://localhost:8000/blog/:blog_id/comment/:id/edit
//嵌套资源生成的上级资源默认id为:blog_id,可以通过vars更改
\think\facade\Route::resource('blog.comment','Comment');//->vars(['blog'=>'blogid']);

//域名路由

//方法1
//\think\facade\Route::domain('news',function(){
//   \think\facade\Route::get('edit/:id','Collect/edit');
//});
//方法2
//\think\facade\Route::domain('news',
//    [
//       'edit/:id'=>'Collect/edit'
//    ]);

//支持多个二级（子）域名,使用相同的路由规则
//\think\facade\Route::domain(['news','blog','live'],function(){
//    \think\facade\Route::get('edit/:id','Collect/edit');
//});

//也可以作为方法，进行二级(子)域名的检测，或完整域名检测
//\think\facade\Route::get('edit/:id','Collect/edit')->domain('news');
//\think\facade\Route::get('edit','Collect/edit');

//\think\facade\Route::domain('news','cs02');

//三级域名
//\think\facade\Route::domain('*.news',function(){
//   \think\facade\Route::get('edit/:id','Collect/edit');
//});

////而直接使用通配符* 则指定所有的二级域名
//\think\facade\Route::domain('*',function(){
//    \think\facade\Route::get('edit/:id','Collect/edit');
//});


//路由URL生成
// URL::build('地址表达式',['参数'],['URL后缀'],['域名'])
// url('地址表达式',['参数'],['URL后缀'],['域名'])

//\think\facade\Route::get('bl/vr','Blog/create');
\think\facade\Route::get('read/:id/:uid','Blog/read');


\think\facade\Route::get('edit/:id','Rely/edit')->cache(3200);  //局部路由设置缓存 cache

//路由中间件
//\think\facade\Route::get('write/:id','Inject/write')->middleware(app\http\middleware\Auth::class);
//\think\facade\Route::get('write/:id','Inject/write')->middleware('Auth');
//\think\facade\Route::get('write/:id','Inject/write')->middleware('app\http\middleware\Auth');
\think\facade\Route::get('write/:id','Inject/write')->middleware(
    ['Auth:ghj']
);

//\think\facade\Route::get('hear/:id','User/hear')->validate(\app\validate\User::class,'edit');

\think\facade\Route::get('hear/:id','User/hear')
    ->validate([
        'id' =>  'number|between:1,10',
        'email' => 'email'
    ],'edit',[
        'id.number' => '编号必须是数字',
        'id.between' => '编号必须是1-10之间',
        'email' => '邮箱格式错误'
    ],true);
return [

];
